<?
include('header.php');
if(!$is_online){
	redirect('index.php');
	exit;
}
?><div class="block medium right">
			<div class="top">
                  <h1>Earn Coins - Facebook</h1>
            </div>
			<div class="content">		
<?
  $sql = $db->Query("SELECT id,facebook,title,cpc FROM `facebook` WHERE `cpc`>'1' AND (`active` = '0' AND `points` >= `cpc`) AND (`id` NOT IN (SELECT `site_id` FROM `liked` WHERE `user_id`='".$data['id']."') AND `user`!='".$data['id']."') ORDER BY `cpc` DESC LIMIT 5");
  
  $ext = $db->GetNumRows($sql);
  $sites = $db->FetchArrayAll($sql);
if($ext > 0){
?>
<p>Get free points by liking other's Facebook Pages or Websites</p>
<script>
function click_callback(id, ncpc){
	document.getElementById("Hint").style.display='block';
	$.ajax({
			type: "GET",
			url: "pages/fbreceive.php",
			data: "data="+id,    
			cache: false,
			success: function(){
				replace_button();
			}
		  });
	c_coins = document.getElementById("currentpoints");
	var cpc = ncpc;
	var coins = c_coins.innerHTML;
	document.getElementById("currentpoints").innerHTML = (1*coins)+(1*cpc);
	removeElement('tbl', id);
}

function removeElement(parentDiv, childDiv){
     if (document.getElementById(childDiv)) {     
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
          parent.removeChild(child);
     }
}
function skipElement(parentDiv, childDiv){
     if (document.getElementById(childDiv)) {     
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
		  $.ajax({
			type: "GET",
			url: "pages/fbreceive.php?step=skip",
			data: "url="+childDiv,        
			success: function(msg){
			$("#Hint").html(msg);
			parent.removeChild(child);
			}
		  });
     }
}
function replace_button(){ $.get('pages/fbmore.php', function(html){ $('div[rel*="replacement"]').first().remove(); $('#tbl').append(html); }); }
function refreshpage(){window.location.reload();}
</script>

<center><div id="Hint"></div></center>
<div id="tbl">
<?
  foreach($sites as $site)
{
?>	
<div class="tbl tbl-facebook" id="<?=$site['id']?>">
	<a href="#" class="close" onclick="skipElement('tbl','<?=$site['id']?>');">x</a>
	<div><iframe src="pages/fbt.php?url=<?=$site['id']?>" width="120" height="24" frameborder="0" allowtransparency="true" scrolling="no"></iframe></div>
	<div class="title"><a href="<?=$site['facebook']?>" target="_blank" style="color:blue;"><?=$site['title']?></a></div>
	<div class="points">Coins: <b><?=$site['cpc']?></b></div>
</div>
<?}?>
</div>
<br />
<div class='infobox'><form action='' method='' onsubmit='refreshpage();'><input name='refresh' type='submit' value='Refresh'></form></div>
<?}else{?>
<div class="msg">
<div class="error">Sorry, there are no more coins to be earned at the moment. Please try again later.</div>
<div class="info"><a href="buy.php"><b>Feel like you need more coins? You can purchase them now!</b></a></div></div>
<?}?>
				</div>
			</div>		
<?include('footer.php');?>